package com.ziyun.erp.web.modules.store.storeProductPrice.controller;

import java.util.Arrays;
import java.util.Map;

import com.ziyun.erp.modules.store.storeProductPrice.entity.StoreProductPriceEntity;
import com.ziyun.erp.modules.store.storeProductPrice.service.StoreProductPriceService;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 门店产品阶梯价
 *
 * @author gaosheng
 * @email 
 * @date 2018-10-13 13:26:06
 */
@RestController
@RequestMapping("store/storeproductprice")
public class StoreProductPriceController {
    @Autowired
    private StoreProductPriceService storeProductPriceService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("store:storeproductprice:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = storeProductPriceService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{stepId}")
    @RequiresPermissions("store:storeproductprice:info")
    public R info(@PathVariable("stepId") Integer stepId){
        StoreProductPriceEntity storeProductPrice = storeProductPriceService.selectById(stepId);

        return R.ok().put("storeProductPrice", storeProductPrice);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("store:storeproductprice:save")
    public R save(@RequestBody StoreProductPriceEntity storeProductPrice){
        storeProductPriceService.insert(storeProductPrice);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("store:storeproductprice:update")
    public R update(@RequestBody StoreProductPriceEntity storeProductPrice){
        ValidatorUtils.validateEntity(storeProductPrice);
        storeProductPriceService.updateAllColumnById(storeProductPrice);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("store:storeproductprice:delete")
    public R delete(@RequestBody Integer[] stepIds){
        storeProductPriceService.deleteBatchIds(Arrays.asList(stepIds));

        return R.ok();
    }

}
